﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Web.UI;
using System.Configuration;

namespace ONTS.WEB
{
    public class BaseWebpage : System.Web.UI.Page
    {

        public BaseWebpage()
        {
            var cult = new CultureInfo("en-US");
            System.Threading.Thread.CurrentThread.CurrentCulture = cult;
            System.Threading.Thread.CurrentThread.CurrentUICulture = cult;
            //if (Session["LOGIN"] == null || Session["LOGIN"] == "")
            //{
            //    Response.Redirect("../Views/AccessDeniedPage.aspx");
            //}
        }

        private string _swork = "";
        protected string startwork
        {
            get { return ConfigurationManager.AppSettings["startworktime"].ToString(); }
        }

        private string _endtwork;
        protected string endtwork
        {
            get { return ConfigurationManager.AppSettings["endworktime"].ToString(); }
        }

        protected void ShowSaveSuccessRedirect()
        {
            Random rnd = new Random();  // creates a number between 1 and 6
            int rndNum = rnd.Next(50);

            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {alert('บันทึกข้อมูลเรียบร้อย'); window.location = ((document.URL.indexOf('?') != -1) ? document.URL + '&rndn=" + rndNum + "' : document.URL + '?rndn=" + rndNum + "');}, 500);", true);
        }


        protected void ShowSaveSuccess()
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {alert('บันทึกข้อมูลเรียบร้อย');}, 500);", true);

        }


        protected void ShowSaveSuccess(string redirectURL)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {alert('บันทึกข้อมูลเรียบร้อย'); window.location = ('" + redirectURL + "');}, 500);", true);

        }


        protected void ShowSaveNotChange()
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {alert('ไม่มีการเปลี่ยนแปลงข้อมูล');}, 500);", true);

        }


        protected void ShowAlert(string msg)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {alert('" + msg + "');}, 500);", true);

        }

        protected void EnableRemindSave(string act)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "setTimeout(function () {  $(window)." + act + "('beforeunload', confirmExit);  }, 500);", true);
        }



        protected void OpenNewWindow(string querystring, Int32 width, Int32 height)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "window.open('" + querystring + "');", true);

        }

    }
}